<?php
final class HouseKeepingPresetMessageModel {
	private $mysql;
	private $tableName = 'HouseKeepingPresetMessage';
	public $idRowName = 'HouseKeepingPresetMessage_ID';
	public $CatidRowName = 'HouseKeepingPresetMessageCat_ID';
	public $IsCatRowName = 'HouseKeepingPresetMessage_IsCat';
	public $maxRowName = 'HouseKeepingPresetMessage_MAX';
	public $CountRowName = 'HouseKeepingPresetMessage_Count';
	public $IsNeedDateTimeRowName = 'HouseKeepingPresetMessage_IsNeedDateTime';
	public $IsNeedAdultsRowName = 'HouseKeepingPresetMessage_IsNeedAdults';
	public $IsNeedKidsRowName = 'HouseKeepingPresetMessage_IsNeedKids';
	public $IsNeedSeniorsRowName = 'HouseKeepingPresetMessage_IsNeedSeniors';
//	public $IsNeedPeopleRowName = 'HouseKeepingPresetMessage_IsNeedPeople';
	public $IsNeedRemindingCall = 'HouseKeepingPresetMessage_IsNeedRemindingCall';

	public function __construct ($mysql) {
		$this->mysql = $mysql;

	}

	public function GetHouseKeepingCatByID ($catid) {
		$ref = NULL;
//, `%s`, `%s`, `%s`, `%s`
		$sqlresult = $this->mysql->query (sprintf ('SELECT `%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s` FROM `%s` WHERE `%s`=1 AND `%s`=%d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->CatidRowName), $this->mysql->escape_string ($this->maxRowName), $this->mysql->escape_string ($this->IsCatRowName), $this->mysql->escape_string ($this->IsNeedDateTimeRowName), $this->mysql->escape_string ($this->IsNeedAdultsRowName), $this->mysql->escape_string ($this->IsNeedKidsRowName), $this->mysql->escape_string ($this->IsNeedSeniorsRowName), $this->mysql->escape_string ($this->IsNeedRemindingCall), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->IsCatRowName), $this->mysql->escape_string ($this->CatidRowName), $catid));
		$len = $sqlresult->affected_rows ();
		if ($len > 0) {
			$ref = $sqlresult->fetch_array ();
		}
		$sqlresult->free_result ();
		return $ref;
	}

	public function GetHouseKeepingByCatID ($catid) {
		$ref = array ();
		$sqlresult = $this->mysql->query (sprintf ('SELECT `%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s` FROM `%s` WHERE `%s`=0 AND `%s`=%d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->CatidRowName), $this->mysql->escape_string ($this->maxRowName), $this->mysql->escape_string ($this->IsCatRowName), $this->mysql->escape_string ($this->IsNeedDateTimeRowName), $this->mysql->escape_string ($this->IsNeedAdultsRowName), $this->mysql->escape_string ($this->IsNeedKidsRowName), $this->mysql->escape_string ($this->IsNeedSeniorsRowName), $this->mysql->escape_string ($this->IsNeedRemindingCall), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->IsCatRowName), $this->mysql->escape_string ($this->CatidRowName), $catid));
		/*$len = $sqlresult->affected_rows ();
		if ($len > 0) {
			$ref = $sqlresult->fetch_array ();
		}*/
		while ($data = $sqlresult->fetch_array ()) {
			$ref[] = $data;
		}
		$sqlresult->free_result ();
		return $ref;
	}

	public function GetHouseKeepingByID ($id) {
		$ref = array ();
		$sqlresult = $this->mysql->query (sprintf ('SELECT `%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s` FROM `%s` WHERE `%s`=%d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->CatidRowName), $this->mysql->escape_string ($this->maxRowName), $this->mysql->escape_string ($this->IsCatRowName), $this->mysql->escape_string ($this->IsNeedDateTimeRowName), $this->mysql->escape_string ($this->IsNeedAdultsRowName), $this->mysql->escape_string ($this->IsNeedKidsRowName), $this->mysql->escape_string ($this->IsNeedSeniorsRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->idRowName), $id));
		while ($data = $sqlresult->fetch_array ()) {
			$ref[] = $data;
		}
		$sqlresult->free_result ();
		return $ref;
	}

/*

	public function GetHouseKeepingPresetMessageCount ($lang = NULL) {
		$ref = 0;
		$sql = '';
		if ($lang == NULL) {
			$sql = sprintf ('SELECT COUNT(*) AS `%s` FROM `%s`;', $this->mysql->escape_string ($this->CountRowName), $this->mysql->escape_string ($this->tableName));
		} else {
			$sql = sprintf ('SELECT COUNT(*) AS `%s` FROM `%s` WHERE `%s`=\'%s\';', $this->mysql->escape_string ($this->CountRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($lang));
		}
		$sqlresult = $this->mysql->query ($sql);
		$len = $sqlresult->num_rows ();
		if ($len > 0) {
			$data = $sqlresult->fetch_array ();
			$ref = $data[$this->CountRowName];
		}
		$sqlresult->free_result ();
		return $ref;
	}
///////
	public function CheckHouseKeepingPresetMessageItemExist ($ID) {
		$ref = NULL;
		$sqlresult = $this->mysql->query (sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` WHERE `%s`=%d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($ID)));
		$len = $sqlresult->affected_rows ();
		if ($len > 0) {
			$ref = $sqlresult->fetch_array ();
		}
		$sqlresult->free_result ();
		return $ref;
	}

	public function GetHouseKeepingPresetMessageItems ($offset, $count, $lang = NULL) {
		$ref = array ();
		$sql = '';
		if ($lang == NULL) {
			$sql = sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` LIMIT %d, %d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($offset), $this->mysql->escape_string ($count));
		} else {
			$sql = sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` WHERE `%s`=\'%s\' LIMIT %d, %d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($lang), $this->mysql->escape_string ($offset), $this->mysql->escape_string ($count));
		}
		$sqlresult = $this->mysql->query ($sql);
		while ($data = $sqlresult->fetch_array ()) {
			$ref[] = $data;
		}
		$sqlresult->free_result ();
		return $ref;
	}

	public function DelHouseKeepingPresetMessageItem ($id) {
		$len = 0;
		$sqlresult = $this->mysql->query (sprintf ('DELETE FROM `%s` WHERE `%s`=\'%s\';', $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($id)));
		$len = $sqlresult->affected_rows ();
		$sqlresult->free_result ();
		return $len;
	}

	public function AddHouseKeepingPresetMessageItem ($description, $lang) {
		$sqlresult = $this->mysql->query (sprintf ('INSERT INTO `%s` (`%s`, `%s`) VALUES (\'%s\', \'%s\');', $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($description), $this->mysql->escape_string ($lang)));
		$sqlresult->free_result ();
	}

	public function EditHouseKeepingPresetMessageItem ($description, $lang, $id) {
		$sqlresult = $this->mysql->query (sprintf ('UPDATE `%s` SET `%s`=\'%s\', `%s`=\'%s\' WHERE `%s`=%d;', $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($description), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($lang), $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($id)));
		$sqlresult->free_result ();
	}*/
}
?>
